package com.baizhi.action;

import com.baizhi.entity.Order;
import com.baizhi.entity.OrderItem;
import com.baizhi.service.OrderItemService;
import com.baizhi.service.OrderService;
import com.baizhi.service.impl.OrderItemServiceImpl;
import com.baizhi.service.impl.OrderServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class OrderAction {
    private List<Order> orders;
    private String orderId;
    private List<OrderItem> orderItems;

    private Order order;
    private PageInfo<Order> pageInfo;
    private Integer pageNum;


    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public List<Order> getOrders() {
        return orders;
    }

    public void setOrders(List<Order> orders) {
        this.orders = orders;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public PageInfo<Order> getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(PageInfo<Order> pageInfo) {
        this.pageInfo = pageInfo;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public String selectAllOrder(){
        OrderService orderService=new OrderServiceImpl();
        if(pageNum==null){
            pageNum=1;
        }
        PageHelper.startPage(pageNum,4);
        orders=orderService.selectAllOrder();
        pageInfo=new PageInfo<>(orders,5);
        return "success";
    }

    public String showOrderDetail(){
        OrderService orderService=new OrderServiceImpl();
        OrderItemService orderItemService=new OrderItemServiceImpl();
        order = orderService.selectOrderById(orderId);
        orderItems=orderItemService.selectOrderForOrderItemsById(orderId);
        return "showOrderDetail";
    }
}
